package flex.cc.medical.service.impl;

import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.springframework.stereotype.Service;

import flex.cc.medical.dto.entity.ImportCardEntity;
import flex.cc.util.ExportUtil;

@Service("exportCardService")
public class ExportCardService {

	/**
	 * 
	 * @author WANGCONG
	 * 2022年2月7日上午10:45:17
	 * @desc 医护类卡券模板下载
	 */
	@SuppressWarnings("deprecation")
	public void downLoadTemplate(HttpServletRequest request, HttpServletResponse response, String fileParentPath, String fileName) {
		// 表名、表头数据
        String title = fileName;
        String[] headers = {"类型编码","类型名称","服务商名称","卡券序列码","激活兑换码"};
        String[] fields = {"activityId","activityName","serviceName","cardNum","activateCode"};
        List<ImportCardEntity> records = new ArrayList<>();
        try {
            SXSSFWorkbook wb = ExportUtil.createWorkbook(10, false);//创建工作簿对象
//            ExportUtil.exportExcel(title, headers, fields, 0, wb, records);
            ExportUtil.downLoadMedicalTemplate(title, headers, fields, 0, wb, records);
            File fileParent = new File(fileParentPath);
            if (!fileParent.exists()) { // 若目录不存在则创建
                fileParent.mkdirs();
            }
            File file = new File(fileParentPath + File.separator + fileName + ".xlsx");
            if (file.exists()) { // 若文件已存在则删除
                file.delete();
            }
            try {
                wb.write(new FileOutputStream(file));
            } catch (Exception e) {
                e.printStackTrace();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
	}
	
	
}
